﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using cs499.Database;

namespace cs499.Classes
{
    public partial class DeleteClass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void CancelButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Classes/ListClasses.aspx");
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            LinkButton classesMenuButton = (LinkButton)Master.FindControl("LoginView").FindControl("ClassesMenuButton");
            classesMenuButton.CssClass = "selected";

            if (HttpContext.Current.Session["CurrentDepartmentId"] != null)
            {
                int CurrentDepartmentId = (int)HttpContext.Current.Session["CurrentDepartmentId"];
                cs499.Database.Department CurrentDepartment = cs499.Database.ListOfDepartment.GetDepartment(ID: CurrentDepartmentId);
                DeleteClassLabel.Text = "Select class to delete from " + CurrentDepartment.Name;

            }
            else
            {
                DeleteClassLabel.Text = "(No departments defined)";
            }
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int CurrentDepartmentId = (int)HttpContext.Current.Session["CurrentDepartmentId"];
            int courseid = (int)GridView1.DataKeys[e.RowIndex].Value;
            cs499.Database.ListOfDepartment.GetDepartment(ID: CurrentDepartmentId).DeleteCourse(ID: courseid);
            //cs499.Database.ListOfDepartment.GetDepartment(ID: CurrentDepartmentId).Places.Remove();
            e.Cancel = true;
            Response.Redirect("~/Classes/DeleteClass.aspx");
        }
    }
}